<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <!-- 左侧占据20分 -->
    <el-col :span="20">
      <span>{{ item.name }}</span>
    </el-col>
    <!-- 左侧占据4分 -->
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col :span="12">{{ item.manager || "负责人" }}</el-col>
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommand">
            <span class="el=dropdown-link">
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown" v-if="item.manager">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item command="edit">编辑部门</el-dropdown-item>
              <el-dropdown-item command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
            <el-dropdown-menu slot="dropdown" v-else>
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
export default {
  name: "TreeTool",
  props: {
    item: {
      type: Object,
      required: true,
    },
  },
  methods: {
    // 下拉菜单的点击
    handleCommand(command) {
      //判断command的值  选择性的执行代码
      //选用switch-case语法  if也一样
      switch (command) {
        case "add":
          //通知父组件
          console.log(this.item);
          this.$emit("add-dept", this.item);
          break;
        case "edit":
          this.$emit("edit-dept", this.item);
          break;
        case "del":
          //通知父组件   并携带参数
          // item是部门对象
          this.$emit("del-dept", this.item.id);

          break;
      }
    },
  },
};
</script>

<style>
</style>